package edu.ccut.saturn.studio.database.adapters;

import java.util.HashMap;
import java.util.Map;

/**
 * 数据库适配器工厂
 * 
 * @author 谷钰
 * @version 1.0 2008.12.02
 * 
 */
public class DatabaseAdapterFactory {

	private static DatabaseAdapterFactory instance = new DatabaseAdapterFactory();

	private static BaseDatatbaseAdapter defaultDatatbaseAdapter = new BaseDatatbaseAdapter();

	private static final String ORACLE = "oracle";

	private static final String MS_SQLSERVER = "sqlserver";
	
	private static final String MYSQL = "mysql";
	
	private static final String DB2 = "db2";
	
	private Map<String, IDatabaseAdapter> adapterMap = new HashMap<String, IDatabaseAdapter>();

	private DatabaseAdapterFactory() {
		adapterMap.put(ORACLE, new OracleAdapter());
		adapterMap.put(MS_SQLSERVER, new SqlServerAdapter());
		adapterMap.put(MYSQL, new MySQLAdapter());
		adapterMap.put(DB2, new DB2Adapter());
	}

	public static DatabaseAdapterFactory getInstance() {
		return instance;
	}

	public IDatabaseAdapter getAdapter(String type) {
		IDatabaseAdapter adapter = adapterMap.get(type.toLowerCase());
		
		if (adapter == null) {
			adapter = defaultDatatbaseAdapter;
		}

		return adapter;
	}
}
